package cn.tedu.baking.service.impl;

import cn.tedu.baking.mapper.IContentMapper;
import cn.tedu.baking.pojo.dto.ContentSaveDTO;
import cn.tedu.baking.pojo.entity.Content;
import cn.tedu.baking.pojo.vo.ContentDetailVO;
import cn.tedu.baking.pojo.vo.ContentIndexVO;
import cn.tedu.baking.pojo.vo.ContentVO;
import cn.tedu.baking.service.IContentService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Author：毕龙
 * Date: 2024/8/15 17:06
 */
@Service
public class ContentServiceImpl implements IContentService {

    @Autowired
    private IContentMapper iContentMapper;

    @Override
    public void saveOrUpdate(ContentSaveDTO contentDTO) {
        Content content = new Content();
        BeanUtils.copyProperties(contentDTO, content);
        if (contentDTO.getId() == null){
            content.setCreateTime(new Date());
            iContentMapper.insert(content);
        }else{
            content.setUpdateTime(new Date());
            iContentMapper.updateContentById(content);
        }


    }

    @Override
    public List<ContentVO> getContentsByCreateBy(Integer createBy, Integer type) {

        return  iContentMapper.getContentsByCreateBy( createBy,  type);
    }

    @Override
    public void deleteContentsById(Integer id) {
        iContentMapper.deleteContentsById(id);
    }

    @Override
    public ContentVO getContentsById(Integer id) {
        return iContentMapper.getContentsById(id);
    }

    @Override
    public List<ContentIndexVO> getContentsByTypeAndCategoryId(Integer type, Integer categoryId) {

        return iContentMapper.getContentsByTypeAndCategoryId(type,categoryId);
    }

    @Override
    public List<ContentIndexVO> getContentsByTypeAndCategoryId(Integer type) {
        return iContentMapper.getContentsByType(type);
    }

    @Override
    public List<ContentIndexVO> getContentslikeTitle(String title) {
        return iContentMapper.getContentslikeTitle(title);
    }

    @Override
    public ContentDetailVO getContentsByContentId(Integer id) {
        return iContentMapper.getContentsByContentId(id);
    }

    @Override
    public int updateViewCountById(Integer id) {
        return iContentMapper.updateViewCountById(id);
    }

    @Override
    public List<ContentIndexVO> getContentsByCreateByAndContentId(Integer createBy, Integer id) {
        return iContentMapper.getContentsByCreateByAndContentId(createBy,id);
    }
}
